# -*- coding: utf8 -*-

import os
import cx_Oracle
import datetime
import psycopg2
import settings

def OutputTypeHandler(cursor, name, defaultType, size,
        precision, scale): 
    if defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): 
        return cursor.var(unicode, size, cursor.arraysize)

class BIDbQuery(object):
    """
    访问经营分析系统
    """

    def __init__(self):
        self.conn = psycopg2.connect(settings.PG_DB)
        self.cursor = self.conn.cursor()

    def close(self):
        self.conn.close()

    def get_data(self):

        self.cursor.execute("select * from jgql limit 10")
        results = []
        for r in self.cursor.fetchall():
            d = dict()
            d['brh_code'] = r[0]
            d['up_brh_code'] = r[1]
            #d['brh_name'] = unicode(r[2], 'utf8')
            results.append(d)
        return results


